<?php
class Booking_model extends Model {

    function Booking_model()
    {
        // Call the Model constructor
        parent::Model();
    }
		
	function insert_booking($data, $nb_passengers)
	{
		$this->db->insert($this->db->dbprefix.'bookings', $data);
		$id_booking =  $this->db->insert_id();
		
		//increase the number of passenger in the table 'tours'
		$tour_id = $data['tour_id'];
		$query = "UPDATE `". $this->db->dbprefix."tours` SET passengers = passengers + $nb_passengers  WHERE id = $tour_id;";
		$this->db->query($query);	
		
		return $id_booking;
	}
	
	function update_booking($booking_id, $data_booking)
	{
		$this->db->where('booking_id', $booking_id);
		$this->db->update($this->db->dbprefix.'bookings', $data_booking);
	}
	
	function get_booking($booking_id)
	{
		$this->db->select($this->db->dbprefix . 'bookings.*');
		$query = $this->db->where($this->db->dbprefix .'bookings.booking_id = ' . $booking_id);
		$query = $this->db->get($this->db->dbprefix . 'bookings');
		$booking = $query->result_array();
		return $booking[0];	
	}
	
}
?>